package com.quartet.modules.vehicle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.vehicle.dao.TVehicleOwnerInfoDao;
import com.quartet.modules.vehicle.dto.TVehicleOwnerInfoAddRequestDto;
import com.quartet.modules.vehicle.entity.TVehicleOwnerInfo;
import com.quartet.modules.vehicle.service.TVehicleOwnerInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 车辆所有人信息表(TVehicleOwnerInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 17:26:35
 */
@Service("tVehicleOwnerInfoService")
public class TVehicleOwnerInfoServiceImpl extends ServiceImpl<TVehicleOwnerInfoDao, TVehicleOwnerInfo> implements TVehicleOwnerInfoService {

    /**
     * 添加车辆所有人信息
     *
     * @param tVehicleOwnerInfoAddRequestDto
     */
    @Override
    public void addVehicleOwnerInfo(TVehicleOwnerInfoAddRequestDto tVehicleOwnerInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tVehicleOwnerInfoAddRequestDto)) {
            TVehicleOwnerInfo tVehicleOwnerInfo = BeanUtil.copyProperties(tVehicleOwnerInfoAddRequestDto, TVehicleOwnerInfo.class);
            this.baseMapper.insert(tVehicleOwnerInfo);
        }
    }

    /**
     * 功能描述: 修改车辆所有人信息
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2021/5/13 16:15
     * @param tVehicleOwnerInfoAddRequestDto
     * @return void
     */
    @Override
    public void updateVehicleOwnerInfo(TVehicleOwnerInfoAddRequestDto tVehicleOwnerInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tVehicleOwnerInfoAddRequestDto)) {
            TVehicleOwnerInfo tVehicleOwnerInfo = BeanUtil.copyProperties(tVehicleOwnerInfoAddRequestDto, TVehicleOwnerInfo.class);
            this.baseMapper.updateById(tVehicleOwnerInfo);
        }
    }

    /**
     * 根据车辆编码删除车辆所有人信息
     * @param vehicleCode
     */
    @Override
    public void deleteVehicleOwnerInfo(String vehicleCode) {
        this.baseMapper.delete(new QueryWrapper<TVehicleOwnerInfo>().lambda().eq(TVehicleOwnerInfo::getVehicleCode,vehicleCode));
    }

    /**
     * 根据车辆编码查询车辆所有人信息
     * @param vehicleCode
     * @return
     */
    @Override
    public TVehicleOwnerInfoAddRequestDto selectVehicleOwnerInfo(String vehicleCode) {
        TVehicleOwnerInfo tVehicleOwnerInfo = this.baseMapper.selectOne(new QueryWrapper<TVehicleOwnerInfo>().lambda().eq(TVehicleOwnerInfo::getVehicleCode, vehicleCode));
        TVehicleOwnerInfoAddRequestDto tVehicleOwnerInfoAddRequestDto = BeanUtil.copyProperties(tVehicleOwnerInfo, TVehicleOwnerInfoAddRequestDto.class);
        return tVehicleOwnerInfoAddRequestDto;
    }
}
